- interpolation algorithms in Xi -
To fit a spline under tension at the points {0, 0.1, 0.2, ..., 4.0} to the data points (x,y) use the spline function
( 1)>x={1,2,3,3.5}; ( 2)>y={0.1,4.0,5.0,3.0}; ( 3)>xfit=dincarr(41)/10. /* xfit={0, 0.1, 0.2 ,...., 4.0} */ ( 4)>tension=1.0 ( 5)>yfit=spline(x,y,xfit,tension);The optional tension (default is zero) parameter controls the smoothness of the fitted curve. When tension is set to zero the curve is nearly a cubic spline.
You can determine a parameteric spline (an arbitrary curve in the plane). Then the spline curve is mapped in the interval (0,1).
( 6)>i=dincarr(60)/10. ( 7)>x=cos(i) /* circle */ ( 8)>y=sin(i) ( 9)>in=dincarr(1000)/1000. /* spline ,mapped in (0,1) */ ( 9)>[xn,yn]=spline_curve(x,y,in,\tension=1);A closed spline curve can also be computed by using the parameter "closed".
( 10)>[xn,yn]=spline_curve(x,y,in,\closed);
If you have to grid a set of data points in a two dimensional plane (scattered data interpolation problem) use the spline2d function which perform a smooth interpolation of scattered data by local thin splines. This function may be helpful to generate contour or surface plots of scattered data points. The first three parameters of the function contain the x,y and z coordinates of the data points. The next two parameters are the x and y coordinates at which the interpolation function is to be calculated. The additional parameter nppr gives the desired average number of points per region (default 10). The result is a two dimensional array containing the gridded z values.
( 11)>x={0,3,5,7,4,8}; y={2,0,4,3,1,8}; z={3,5,6,4,-2,6}; /* data points */ ( 12)>xn=dincarr(10); yn=dincarr(10); /* 10x10 grid for the interplotion function */ ( 13)>f=spline2d(x,y,z,xn,yn,\nppr=5); ( 14)>contour(f,\curve);The result may look like this
In Addition the function resize performs a multi dimensional linear interpolation as shown in the introduction about array's